import pandas as pd

pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)

df = pd.read_excel('超市营业额2.xlsx')
print('每天交易总额变化情况'.ljust(20, '='))

# 计算每天交易总额的变化情况
daily_total = df.groupby(by='日期').sum(numeric_only=True)['交易额']
df_diff = daily_total.diff()

# 格式化，正数前面带加号
print(df_diff.map(lambda num: '%+.2f' % num)[:5])

print('与7天前交易总额相比的变化情况'.ljust(20, '='))
print(daily_total.diff(periods=7)[:20])

print('张三的每天交易总额变化情况'.ljust(20, '='))
print(df[df['姓名'] == '张三'].groupby(by='日期').sum(numeric_only=True)['交易额'].diff()[:5])
